package com.dmxh.controller;

import com.dmxh.result.Result;
import com.dmxh.service.GoodsService;
import com.dmxh.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    @PostMapping("/addInfo")
    public Result addInfo(@RequestBody GoodsVo goodsVo, HttpServletRequest request) {
        String username = request.getHeader("username");//获取当前登录的用户信息,保存到表里
        goodsVo.setSellerId(username);
        goodsService.addInfo(goodsVo);
        return Result.ok();
    }


    /*根据商品id查询出详情页信息*/
    @GetMapping("/queryGoodsAllById/{goodsid}")
    public Result queryGoodsById(@PathVariable("goodsid") long goodsid) {
        return Result.ok().setData(goodsService.queryGoodsById(goodsid));
    }


    /*商品审核crud*/
    @GetMapping("/queryAllGoods")
    public Result queryAllGoods() {
        return Result.ok().setData(this.goodsService.queryAllGoods());
    }

    @PostMapping("/saveGoods")
    public Result saveGoods(@RequestBody GoodsVo goodsVo) {
        return Result.ok().setData(this.goodsService.saveGoods(goodsVo));
    }

    @PutMapping("/updateGoods")
    public Result updateGoods(@RequestBody GoodsVo goodsVo) {
        return Result.ok().setData(this.goodsService.updateGoods(goodsVo));
    }

    @DeleteMapping("/deleteGoods")
    public Result deleteGoods(@RequestParam Long id) {
        return Result.ok().setData(this.goodsService.deleteGoods(id));
    }

    /*商品审核*/
    @PutMapping("/auditStatusGoods")
    public Result auditStatusGoods(@RequestParam Long goodsId, @RequestParam String status) {
        return Result.ok().setData(this.goodsService.auditStatusGoods(goodsId, status));
    }

}
